DEW.FinderController = function() {};

$.extend(DEW.FinderController.prototype, {
    render: function() {
        DEW.ViewManager.removeAll();
        this.displayLayout();
        this.displayHeader();
        this.displayBody();
       
    },

    displayLayout: function() {
        var finderLayout = new DEW.FinderLayout();
        finderLayout.render();
        $(finderLayout.el).appendTo("#content");
        DEW.ViewManager.addView(finderLayout);
    },

    displayHeader: function() {
        var header = new DEW.Header();
        header.render();
        /* $(header.el).appendTo("#header"); */
        $("#header").html(header.el);
        
        var loginController = new DEW.LoginController();        
        $("#btnLogin").click(function(){
            DEW.ViewManager.remove(body);
            loginController.render();
             $(".page-content").html(loginController.el);
            DEW.ViewManager.addView(loginController);
        });
        
        var registerController = new DEW.RegisterController();        
        $("#btnResgistrate").click(function(){
            debugger;
            DEW.ViewManager.remove(body);
            registerController.render();
            $(".page-content").html(registerController.el);
            DEW.ViewManager.addView(registerController);
        });
        
       var finderController = new DEW.FinderController();
        $("#btnTipoCocina").click(function(){
            debugger;
            DEW.ViewManager.remove(body);
        finderController.render();       
        /* $(body.el).appendTo(".page-content"); */
        $(".page-content").html(finderController.el);      
        DEW.ViewManager.addView(finderController);
        });
        DEW.ViewManager.addView(header);
    },
    displayBody: function() {

        //Cargando categorias
        var categoriesCollection = new DEW.CategoriesCollection();
        categoriesCollection.fetch({reset: true});

        var sidebar = new DEW.Sidebar({
            model: categoriesCollection
        });

        sidebar.on("changeCategory",function(categoryId) {
            listView.categoryId = categoryId;
            listView.render();
        });

        $(sidebar.el).appendTo(".sidebar");
        DEW.ViewManager.addView(sidebar);

        //Cargando lista de datos
        var listCollection = DEW.StoreManager.get('listCollection');
        if (listCollection === null) {
            listCollection = new DEW.ListCollection();
            listCollection.fetch({reset:true});
        }

        //Creando la vista y asociandole el modelo
        var listView = new DEW.List({
            model: listCollection
        });
        $(listView.el).appendTo(".page-content");
        DEW.ViewManager.addView(listView);
    }

   
});